package com.example.day16_mp;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import androidx.fragment.app.Fragment;

import java.util.ArrayList;
import java.util.List;

public class BlankFragment3 extends Fragment {

    List<Music.DataBean> list = new ArrayList<>();
    MusicAdapter musicAdapter;
    private ListView lvSql;

    public BlankFragment3() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_blank3, container, false);
        initView(view);
        musicAdapter = new MusicAdapter(list,getContext());
        lvSql.setAdapter(musicAdapter);

        return view;
    }

    private void initView(View view) {
        lvSql = (ListView) view.findViewById(R.id.lv_sql);
    }

    @Override
    public void onResume() {
        super.onResume();
        List<Music.DataBean> query = SqlUtils.getInstance(getContext()).query();
        list.clear();
        list.addAll(query);
        MusicUtils.getInstance().setList(query);//重新设置播放列表的数据源
        musicAdapter.notifyDataSetChanged();
    }
}